package Sun

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.mllib.evaluation.BinaryClassificationMetrics
import org.apache.spark.mllib.regression.LabeledPoint
import org.apache.spark.rdd.RDD

/**
 * Created by SHANGMAI on 2016/10/12.
 */
object MutiTouchTest {


  //进行测试的代码
  def main(args: Array[String]): Unit = {

    val sparkConf = new SparkConf().setAppName("MutiTouchTest").set("spark.hadoop.validateOutputSpecs", "false")
    val sc = new SparkContext(sparkConf)
    //设置初始文件夹位置

    //直接调用train的方法 分割数据
    val (train,test) = MutiTouchTrain.prepareData(sc)

    val trainRoc =   testSample(sc,train)
    val trainTest =   testSample(sc,test)



    //给出两者关系



  }


  //给出测试样本 测试数据，来进行样本的测试
  //计算样本的ROC等值
  def testSample(sc:SparkContext,test:RDD[LabeledPoint]): Double =
  {
    //给出相应的模型，进行预测 来进行判断
    val model = new MutiTouchModel()
    model.loadModel(BasicFunction.mode)
    val modelboard = sc.broadcast(model)
    // Compute raw scores on the test set.
    val scoreAndLabels = test.map(point =>{
      val score = modelboard.value.predict(point.features)
      (score, point.label)}
    )


    // Get evaluation metrics.
    val metrics = new BinaryClassificationMetrics(scoreAndLabels)

    //计算ROC的面积
    val auROC = metrics.areaUnderROC()

    return  auROC

  }

}
